package leetcode.day;

import org.omg.CORBA.MARSHAL;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// 1380. 矩阵中的幸运数
public class LuckyNumbers {
    public static void main(String[] args) {
        int[][] data = {{3,6}, {7,1}, {4, 8}};
        System.out.println(luckyNumbers(data));
    }

    public static List<Integer> luckyNumbers(int[][] matrix) {
        List<Integer> res = new ArrayList<>();

        int min = Integer.MAX_VALUE;
        int p = 0, q = 0;


        for (int i = 0; i < matrix.length; i++) {
            min = matrix[i][0];
            for (int j = 0; j < matrix[0].length; j++) {

                if (matrix[i][j] < min) {
                    min = matrix[i][j];

                    p = i;
                    q = j;
                }
            }
            int max = Integer.MIN_VALUE;
            for (int k = 0; k < matrix.length; k++) {
                max = Math.max(max, matrix[k][q]);
            }
            if (max == min) {
                res.add(min);
            }
        }
        return res;

    }

}
